---
title: "update_key"
description: "Updates the configuration of a key"
---

> @spec update_key(binary(), map()) :: :ok

Updates the configuration of a key.

Takes in a `key_id` argument and a map whose members are optional
but must have at most 1 member present.

To delete a field, set it to `nil`.

## Request

<ParamField path="keyId" type="string" required>
  The ID of the key you want to modify.
</ParamField>

<ParamField body="name" type="string | nil">
  Update the name of the key.
</ParamField>

<ParamField body="ownerId" type="string | nil">
  Update the owner id of the key.
</ParamField>

<ParamField body="meta" type="JSON | nil">
  Update the metadata of a key. You will have to provide the full metadata
  object, not just the fields you want to update.
</ParamField>

<ParamField body="expires" type="int | nil">
  Update the expire time of a key.

The expire time is a unix timestamp in milliseconds.

</ParamField>

<ParamField body="ratelimit" type="Object | nil" >

Unkey comes with per-key ratelimiting out of the box.

  <Expandable title="properties">

  <ParamField body="type" type="string" required>
  Either `fast` or `consistent`.

Read more [here](/apis/features/ratelimiting)

  </ParamField>
  <ParamField body="limit" type="int" required>
  The total amount of burstable requests.

  </ParamField>
  <ParamField body="refillRate" type="int" required>
  How many tokens to refill during each `refillInterval`
  </ParamField>
  <ParamField body="refillInterval" type="int" required>
  Determines the speed at which tokens are refilled.

In milliseconds

  </ParamField>
 </Expandable>
</ParamField>

<ParamField body="remaining" type="int | nil">
  Update the expire time of a key.

The expire time is a unix timestamp in milliseconds.

</ParamField>

## Response

Returns an atom `:ok`

<RequestExample>

```elixir
   try do
     :ok = UnkeyElixirSdk.update_key("key_cm9vdCBvZiBnb29kXa", %{
                "name" => "my_new_key",
                "ratelimit" => %{
                "type" => "fast",
                "limit" => 15,
                "refillRate" => 2,
                "refillInterval" => 500
                },
                "remaining" => 3
            })

    catch
        err ->
          Logger.error(err)
      end
```

</RequestExample>

<ResponseExample>

```elixir
:ok
```

</ResponseExample>
